package cn.shanke.imousdk.api;

import java.io.Serializable;

public class JsonResult implements Serializable {
	
	public static final int CODE_SUCCESS = 200;
	public static final int CODE_ERROR = 500;
	
	private static final long serialVersionUID = 1L;
	private int code;
	private String message;
	private Object data;
	private int errorCode;
	
	public JsonResult() {}
	public JsonResult(int code) {
		this.code=code;
	}
	public JsonResult(int code, String message) {
		this(code, message, null);
	}
	
	public JsonResult(int code, String message, Object data) {
		this(code, message, data, 0);
	}
	
	public JsonResult(int code, String message, Object data, int errorCode) {
		this.code=code;
		this.message = message+"";
		this.data=data;
		this.errorCode=errorCode;
	}
	
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
	
	public int getErrorCode() {
		return errorCode;
	}
	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}


	public JsonResult withMessage(String message) {
		this.message = message;
		return this;
	}
	public JsonResult withData(Object data) {
		this.data = data;
		return this;
	}
	
	public static JsonResult error(int errorCode,String message) {
		return new JsonResult(CODE_ERROR,message);
	}
	
	public static JsonResult error(String message) {
		return new JsonResult(CODE_ERROR,message);
	}

	public static JsonResult success() {
		return new JsonResult(CODE_SUCCESS);
	}

}
